import { apiClient } from './client';
import { API_ENDPOINTS } from './config';
import type {
  PaginationParams,
  PaginatedResponse
} from '../types/api';
import type {
  RechargeRequest,
  RechargeInfo,
  RechargeListItem,
  WithdrawRequest,
  WithdrawListItem,
  BalanceLogItem,
  AddRechageWalletRequest,
} from '../types/amount';
// Recharge APIs
export const rechargeApi = {
  // Get recharge information
  getRechargeInfo: async (data: RechargeRequest): Promise<RechargeInfo> => {
    return apiClient.post(API_ENDPOINTS.RECHARGE_INFO, data);
  },

  // Get recharge list
  getRechargeList: async (params: PaginationParams): Promise<PaginatedResponse<RechargeListItem>> => {
    return apiClient.get(API_ENDPOINTS.RECHARGE_LIST, { params });
  },

  // Cancel recharge
  cancelRecharge: async (orderId: string): Promise<void> => {
    return apiClient.post(API_ENDPOINTS.RECHARGE_CANCEL, { RechargeId: parseInt(orderId) });
  },

  // Confirm recharge
  confirmRecharge: async (orderId: string): Promise<void> => {
    return apiClient.post(API_ENDPOINTS.RECHARGE_CONFIRM, { RechargeId: parseInt(orderId) });
  },

  // Get recharge order info
  getRechargeOrderInfo: async (rechargeId: string): Promise<RechargeInfo> => {
    return apiClient.get(API_ENDPOINTS.RECHARGE_ORDER_INFO, {
      params: { RechargeId: parseInt(rechargeId) }
    });
  },
  // 获取充值网络
  getRechargeNetwordList: async () => {
    return apiClient.get(API_ENDPOINTS.RECHARGE_NETWORK_LIST);
  },
  // 获取钱包地址
  getRechageWalletList: async (params: any) => {
    return apiClient.get(API_ENDPOINTS.RECHARGE_WALLET_LIST, { params });
  },
  deleteRechageWallet: async (AddressId: string): Promise<void> => {
    return apiClient.get(API_ENDPOINTS.RECHARGE_DELETE, {
      params: { AddressId: parseInt(AddressId) }
    });
  },
  addRechageWallet: async (data: AddRechageWalletRequest): Promise<void> => {
    return apiClient.post(API_ENDPOINTS.RECHARGE_ADD, data);
  },
};

// Withdraw APIs
export const withdrawApi = {
  // Submit withdraw request
  withdraw: async (data: WithdrawRequest): Promise<void> => {
    return apiClient.post(API_ENDPOINTS.WITHDRAW, data);
  },

  // Get withdraw list
  getWithdrawList: async (params: PaginationParams): Promise<PaginatedResponse<WithdrawListItem>> => {
    return apiClient.get(API_ENDPOINTS.WITHDRAW_LIST, { params });
  },

  // Cancel withdraw
  cancelWithdraw: async (orderId: string): Promise<void> => {
    return apiClient.post(API_ENDPOINTS.WITHDRAW_CANCEL, { orderId });
  },


};

// Balance Log APIs
export const balanceApi = {
  // Get balance log list
  getBalanceLogs: async (params: PaginationParams & {
    logScene?: number; // 20:充值,30:提现,40:卡充值,100:手续费
  }): Promise<PaginatedResponse<BalanceLogItem>> => {
    return apiClient.get(API_ENDPOINTS.BALANCE_LOG_LIST, { params });
  },
};

// Export all APIs
export const amountApi = {
  recharge: rechargeApi,
  withdraw: withdrawApi,
  balance: balanceApi,
};